import 'package:flutter/material.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class CommonTabBar extends StatelessWidget {
  final TabController tabController;
  final List<Widget> tabs;
  final bool isScrollable;
  final Color? unselectedLabelColor;
  final Color? labelColor;
  final Function(int)? onTap;
  final EdgeInsetsGeometry? labelPadding;
  final EdgeInsetsGeometry? tabContentPadding;
  final TextStyle? unselectedLabelStyle;
  final TextStyle? labelStyle;
  final Decoration? indicator;
  final EdgeInsetsGeometry? indicatorPadding;
  final TabBarIndicatorSize? indicatorSize;

  const CommonTabBar({
    super.key,
    required this.tabController,
    required this.tabs,
    this.onTap,
    this.labelColor,
    this.isScrollable = true,
    this.unselectedLabelColor,
    this.labelPadding,
    this.tabContentPadding,
    this.unselectedLabelStyle,
    this.labelStyle,
    this.indicator,
    this.indicatorPadding,
    this.indicatorSize,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 40,
      child: TabBar(
        controller: tabController,
        padding: tabContentPadding ?? EdgeInsets.symmetric(horizontal: 16.w),
        onTap: onTap,
        tabAlignment: isScrollable ? TabAlignment.start : null,
        labelPadding: labelPadding ?? EdgeInsets.only(right: 24.w),
        labelColor: labelColor ?? AppColor.primary,
        unselectedLabelColor: unselectedLabelColor ?? AppColor.textPrimary.withOpacity(0.7),
        unselectedLabelStyle: unselectedLabelStyle ??
            TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600),
        labelStyle: labelStyle ??
            TextStyle(fontSize: 16.sp, fontWeight: FontWeight.w600),
        dividerColor: Colors.transparent,
        isScrollable: isScrollable,
        indicator: indicator ??
            UnderlineTabIndicator(
              borderSide: const BorderSide(
                width: 2,
                color: AppColor.primary,
              ),
              insets: EdgeInsets.symmetric(horizontal: 6.w),
            ),
        indicatorPadding: indicatorPadding ?? const EdgeInsets.only(bottom: 4),
        indicatorSize: indicatorSize,
        indicatorWeight: 0.0,
        splashFactory: NoSplash.splashFactory,
        overlayColor:
            WidgetStateProperty.resolveWith<Color?>((Set<WidgetState> states) {
          return Colors.transparent;
        }),
        tabs: tabs,
      ),
    );
  }
}
